package com.lantosec.hmrp.modules.archives.controller;


import com.lantosec.hmrp.core.kit.PageVO;
import com.lantosec.hmrp.core.log.ControllerLog;
import com.lantosec.hmrp.core.log.LogType;
import com.lantosec.hmrp.modules.archives.entity.UserInfo;
import org.springframework.web.bind.annotation.RequestMapping;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import com.lantosec.hmrp.core.kit.Result;
import com.lantosec.hmrp.modules.archives.service.IUserInfoService;
import com.lantosec.hmrp.modules.archives.vo.UserInfoVO;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

import lombok.extern.log4j.Log4j2;
import org.springframework.web.bind.annotation.RestController;
import com.lantosec.hmrp.core.mvc.BaseController;

/**
 *
 * 用户信息表 控制器
 *
 * @author AutoCode
 * @since 2020-06-09
 */
@Api(value = "用户信息表控制器", tags = "用户信息表控制器")
@RestController
@RequestMapping("/archives/user/info")
@Log4j2
public class UserInfoController extends BaseController {
    @Autowired
    private IUserInfoService service;

    @GetMapping("getUserInfo/{userId}")
    @ApiOperation(value = "查询当前用户信息")
    public Result<UserInfoVO> getUserInfo(@ApiParam(value = "userId", required = true) @PathVariable(name="userId") String userId){
        UserInfoVO userInfoVO = service.getUserInfo(userId);
        return Result.ok(userInfoVO);
    }

    @GetMapping("getIntegrityList")
    @ApiOperation(value = "查询用户信息廉政档案列表")
    public Result<List<UserInfoVO>> getIntegrityList(@ApiParam(value = "name") @RequestParam(name="name",required = false) String name){
        List<UserInfoVO> userInfoVOList = service.getIntegrityList(name);
        return Result.ok(userInfoVOList);
    }

    @GetMapping("getUserInfoVerify")
    @ApiOperation(value = "查询用户信息审核列表")
    public Result<List<UserInfoVO>> getUserInfoVerify(){
        List<UserInfoVO> userInfoVOList = service.getUserInfoVerify();
        return Result.ok(userInfoVOList);
    }

    @GetMapping("getUserInfoHistory/{userId}")
    @ApiOperation(value = "查询用户信息历史列表")
    public Result<List<UserInfoVO>> getUserInfoHistory(@ApiParam(value = "userId", required = true) @PathVariable(name="userId") String userId){
        List<UserInfoVO> userInfoVOList = service.getUserInfoHistory(userId);
        return Result.ok(userInfoVOList);
    }

    @GetMapping("getAll")
    @ApiOperation(value = "查询用户所有列表信息")
    public Result<PageVO<UserInfoVO>> getAll(@ApiParam(value = "分页对象", required = true) PageVO<UserInfo> page,
                                             @ApiParam(value = "name") @RequestParam(name="name",required = false) String name){
        PageVO<UserInfoVO> userInfoVOList = service.getAll(page,name);
        return Result.ok(userInfoVOList);
    }

    @PostMapping("create")
    @ControllerLog(name = "新增用户信息", type = LogType.add)
    @ApiOperation(value = "新增用户信息")
    public Result<String> create(@ApiParam(value = "用户信息表VO对象", required = true) @RequestBody @Validated UserInfoVO vo){
        service.saveUserInfo(vo);
        return Result.ok();
    }

    @PostMapping("saveUserIntegrity")
    @ControllerLog(name = "新增廉政用户信息", type = LogType.add)
    @ApiOperation(value = "新增廉政用户信息")
    public Result<String> saveUserIntegrity(@ApiParam(value = "用户信息表VO对象", required = true) @RequestBody @Validated UserInfoVO vo){
        return Result.ok(service.saveUserIntegrity(vo));
    }

    @PutMapping("update")
    @ControllerLog(name = "修改用户信息", type = LogType.update)
    @ApiOperation(value = "修改用户信息")
    public Result<Void> update(@ApiParam(value = "用户信息表VO对象", required = true) @RequestBody UserInfoVO vo){
        service.updateUserInfo(vo);
        return Result.ok();
    }

    @PutMapping("verifyUserInfo")
    @ControllerLog(name = "修改用户信息审核", type = LogType.update)
    @ApiOperation(value = "审核")
    public Result<Void> verifyUserInfo(@ApiParam(value = "用户信息表VO对象", required = true) @RequestBody UserInfoVO vo){
        service.verifyUserInfo(vo);
        return Result.ok();
    }

    @DeleteMapping(value = "delete/{ids}")
    @ControllerLog(name = "逻辑删除用户信息", type = LogType.delete)
    @ApiOperation("逻辑删除")
    public Result<Void> delete(@ApiParam(value = "ID列表,用逗号分隔", required = true) @PathVariable(name="ids") String ids){
        if(StringUtils.isNotEmpty(ids)){
            service.removeByIds(Arrays.asList(ids.split(",")));
        }
        return Result.ok();
    }

    @GetMapping("getUserRewardsPunish")
    @ApiOperation(value = "查询用户奖惩信息")
    public Result<PageVO<Map<String,Object>>> getUserRewardsPunish(PageVO<Map<String, Object>> page,
                                                        @ApiParam(value = "userId", required = true) @RequestParam(name="userId") String userId){
        PageVO<Map<String,Object>> date = service.getUserRewardsPunish(page,userId);
        return Result.ok(date);
    }

    @GetMapping("getUserAppraisalRecord")
    @ApiOperation(value = "查询用户考评记录")
    public Result<PageVO<Map<String,Object>>> getUserAppraisalRecord(PageVO<Map<String, Object>> page,
                                                                   @ApiParam(value = "userId", required = true) @RequestParam(name="userId") String userId){
        PageVO<Map<String,Object>> date = service.getUserAppraisalRecord(page,userId);
        return Result.ok(date);
    }
}
